package top.buluoluo.ordersservice.dto.request;

import lombok.Data;
import top.buluoluo.ordersservice.entity.OrderItems;
import top.buluoluo.ordersservice.entity.Orders;
import top.buluoluo.ordersservice.enums.OrderDeliveryMethod;
import top.buluoluo.ordersservice.enums.OrderStatus;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

@Data
public class OrderAddRequest {
    private Long userId;
    private BigDecimal originalAmount;
    private BigDecimal discountRate;
    private BigDecimal finalAmount;
    private String deliveryMethod;
    private Map<String, Object> deliveryAddress;

    private String remark;
    private Long productId;
    private Long skuId;
    private Long quantity;
    private BigDecimal subTotal;
//    转换为Orders实体对象
    public Orders toOrders() {
        Orders order = new Orders();
        order.setUserId(this.userId);
        order.setStatus(OrderStatus.CREATED);
        order.setOriginalAmount(this.originalAmount);
        order.setDiscountRate(this.discountRate);
        order.setFinalAmount(this.finalAmount);
        order.setRemark(this.remark);
        order.setDeliveryMethod(OrderDeliveryMethod.valueOf(this.deliveryMethod));
        order.setDeliveryAddress(this.deliveryAddress);
        order.setCreatedAt(new Date());
        return order;
     }
//      转换为OrderItems实体对象
    public OrderItems toOrderItems() {
        OrderItems orderItems = new OrderItems();
        orderItems.setProductId(this.productId);
        orderItems.setSkuId(this.skuId);
        orderItems.setQuantity(this.quantity);
        orderItems.setSubtotal(this.subTotal);
        return orderItems;
    }
}

